package org.apache.james.mime4j.io;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class RootInputStream extends FilterInputStream
{
  private int lineNumber = 1;
  private int prev = -1;
  private boolean truncated = false;

  public RootInputStream(InputStream paramInputStream)
  {
    super(paramInputStream);
  }

  public int getLineNumber()
  {
    return this.lineNumber;
  }

  public int read()
    throws IOException
  {
    int j;
    if (this.truncated)
      j = -1;
    while (true)
    {
      return j;
      int i = this.in.read();
      if ((this.prev == 13) && (i == 10))
        this.lineNumber = (1 + this.lineNumber);
      this.prev = i;
      j = i;
    }
  }

  public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    int k;
    if (this.truncated)
      k = -1;
    while (true)
    {
      return k;
      int i = this.in.read(paramArrayOfByte, paramInt1, paramInt2);
      for (int j = paramInt1; j < paramInt1 + i; ++j)
      {
        if ((this.prev == 13) && (paramArrayOfByte[j] == 10))
          this.lineNumber = (1 + this.lineNumber);
        this.prev = paramArrayOfByte[j];
      }
      k = i;
    }
  }

  public void truncate()
  {
    this.truncated = true;
  }
}